package cn.mn.ac.demo.comsumer;

import cn.mn.ac.rocketmq.consumer.RocketListener;
import cn.mn.ac.rocketmq.annotation.ConsumerListener;
import cn.mn.ac.rocketmq.annotation.OnsConfiguration;
import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.common.protocol.heartbeat.MessageModel;
import lombok.extern.slf4j.Slf4j;


/**
 * @author: zhuCan
 * @date: 2020/1/10 18:03
 * @description:
 */

/**
 * @Component 注册成一个bean
 * @ConsumerListener 标识是一个ons的消息消费者监听器
 * 1. tags:接受带有相关tag的消息
 * 2. consumers启动的实例数量
 * <p>
 * MessageData 为消息体类型class
 * consume 为消费业务逻辑
 */
@Slf4j
@ConsumerListener(topic = "DEV_TEST", tags = "dev_test_tag", group = "DEV_GROUP", messageModel = MessageModel.CLUSTERING)
@OnsConfiguration
public class ExampleConsumerListener implements RocketListener<String> {

    @Override
    public Action consume(Message message, String messageBody, ConsumeContext consumeContext) {
        log.info("Message:{}", message);
        return Action.CommitMessage;
    }
}
